{% extends "templates/atnet_base.html" %}

{% block csslink %}
{{ super() }}
<script src="/media/js/jquery.js"></script>

{% include 'templates/includes_datatable.html' %}
{% include 'templates/includes_jquery_ui.html' %}
<script src="/media/js/form_popup.js"></script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
	$('#lots').dataTable({
		"bPaginate": true,
		"bLengthChange": false,
		"bFilter": true,
		"bSort": true,
		"bInfo": true,
		"bAutoWidth": false,
		"oLanguage": {
			"sUrl": "/media/js/dataTables.{{ app_user.lang }}.txt"
		},
		"bProcessing": true,
		"sAjaxSource": "{{ uri_for('creation_lots', imm_id=immeuble.key().id(), command='list_json') }}",
		"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
			$('td:eq(6)', nRow).html('<a href="javascript:void(0);" id="' + aData[6] + '" class="edit">{{ _("Edit") }}</a>&nbsp;<a href="javascript:void(0);" id="' + aData[6] + '" class="delete">{{ _("Delete") }}</a>');
		}
	});
	
	$('#add-lot').live('click', function(){
		$(this).LaunchPopup(
			{
				TableId: '#lots',
				DivId: '#dialog-form',
				FormId: '#generated-form',
				UrlForm: "{{ uri_for('creation_lots',imm_id=app_user.last_active_immeuble_id, command='add') }}",
				Mode: 'add',
				Title: '{{ _("Add lot") }}',
			}
		)
	});
	
	$('#lots tbody tr a').live('click', function(e) {
		if ($(this).attr('class') == 'edit') {
			$(this).LaunchPopup(
					{
						TableId: '#lots',
						DivId: '#dialog-form',
						FormId: '#generated-form',
						UrlForm: "{{ uri_for('creation_lots', imm_id=app_user.last_active_immeuble_id, command='edit') }}" + e.target.id + "/",
						Mode: 'edit',
						Title: '{{ _("Edit lot") }}',
					}
				)
		}
		if ($(this).attr('class') == 'delete') {
			$(this).LaunchPopup(
					{
						TableId: '#lots',
						DivId: '#dialog-form',
						FormId: '#generated-form',
						UrlForm: "{{ uri_for('creation_lots', imm_id=immeuble.key().id(), command='delete') }}" + e.target.id + "/",
						Mode: 'delete',
						Title: '{{ _("Delete lot") }}',
					}
				)
		}
	});
});
</script>
{% endblock %}

{% block title %} 
	{{ title }}
{% endblock %}

{% block header %}
{{ header }}
{% endblock %}

{% block login%}
{% if show_login %}
{{ super() }}
{% endif %}
{% endblock%}

{% block navigation %}
{{ super() }}
{% endblock %}

{% block section_menu %}
{% include 'templates/includes_creation_menu.html' %}
{% endblock %}

{% block main_content %}
<p>
	<div>
		<a href="javascript:void(0);" id="add-lot">{{ _('Add lot') }}</a>
	</div>
	<br/><br/>
	<div id="demo">
	<table cellpadding="0" cellspacing="0" border="0" class="display" id="lots" width="100%">
		<thead>
			<tr>
				<th>{{ _(fields.number) }}</th>
				<th>{{ _(fields.batiment) }}</th>
				<th>{{ _(fields.lot_type) }}</th>
				<th>{{ _(fields.escalier) }}</th>
				<th>{{ _(fields.etage) }}</th>
				<th>{{ _(fields.surface) }}</th>
				<th width="20"></th>
			</tr>
		</thead>
		<tbody>
		</tbody>
		<tfoot>
			<tr>
				<th>{{ _(fields.number) }}</th>
				<th>{{ _(fields.batiment) }}</th>
				<th>{{ _(fields.lot_type) }}</th>
				<th>{{ _(fields.escalier) }}</th>
				<th>{{ _(fields.etage) }}</th>
				<th>{{ _(fields.surface) }}</th>
				<th></th>
			</tr>
		</tfoot>
	</table>
	</div>
	{% include 'templates/includes_popup_form.html' %}
</p>
{% endblock %}
